package 哈希.字母异位词分组49;

import java.util.*;
import utils.Utils;

public class Solution {
    public static List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> map = new HashMap<>();
        for(String str : strs){
            char[] arr = str.toCharArray();
            Arrays.sort(arr);
            String newStr = new String(arr);
            List<String> list = map.getOrDefault(newStr,new ArrayList<>());
            list.add(newStr);
            map.put(newStr,list);
        }

        return new ArrayList<>(map.values());
    }

    public static void main(String[] args) {
        String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
        Utils.printListList(groupAnagrams(strs));

    }
}
